'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('minaUserCoupon', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        minaCouponType: {
            type: Sequelize.INTEGER(2),
            allowNull: false,
        },
        minaCouponTitle: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        minaCouponQuota: {
            type: Sequelize.INTEGER(6),
        },
        closeAt: {
            type: Sequelize.DATE,
            allowNull: false,
        },
        status: {
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
            allowNull: false,
        },
    }, {
        freezeTableName: true,
        tableName: 'mina_user_coupon',
    })

    Model.associate = function() {
        model.MinaUserCoupon.belongsTo(model.MinaUser)
        model.MinaUserCoupon.belongsTo(model.MinaCoupon)
        model.MinaUser.hasMany(model.MinaUserCoupon)
        model.MinaCoupon.hasMany(model.MinaUserCoupon)
    }

    return Model
}